import subprocess
import os

def handler(event, context):
    if not os.path.exists("/data/sd/models/Stable-diffusion"):
        print("model not found, downloading...")
        result = subprocess.run("bash /code/download.sh", shell=True)
        if result.returncode != 0:
            print("download failed")
            return "failed"
        else:
            print("download success")
            return "success"
    else:
        print("model found, skip download")
        return "success"
